package net.soulwolf.test.poidemo;

import android.content.Context;
import android.content.Intent;
import android.net.Uri;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.view.View;

import java.io.File;

import rx.functions.Action1;

public class MainActivity extends AppCompatActivity {

    public static final String WORD_FILE_NAME = "word.docx";

    private OfficeConverter mOfficeConverter;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        mOfficeConverter = new OfficeConverter(this);
    }

    public void onWordClick(View view){
        Intent intent = new Intent(getContext(),WebActivity.class);
        intent.putExtra(WebActivity.KEY_HTML_URL, "file:///android_asset/" + WORD_FILE_NAME);
        startActivity(intent);
//        mOfficeConverter.wordConvert(WORD_FILE_NAME)
//                .subscribe(new Action1<File>() {
//                    @Override
//                    public void call(File file) {
//                        jumpWeb(file);
//                    }
//                }, new Action1<Throwable>() {
//                    @Override
//                    public void call(Throwable throwable) {
//                        throwable.printStackTrace();
//                    }
//                });
    }

    public Context getContext(){
        return this;
    }

    private void jumpWeb(File file){
        Intent intent = new Intent(getContext(),WebActivity.class);
        intent.putExtra(WebActivity.KEY_HTML_URL, Uri.fromFile(file).toString());
        startActivity(intent);
    }
}
